<script setup lang="ts">
import { ref } from 'vue'
import Versions from './components/Versions.vue'

const ipcHandle = () => window.electron.ipcRenderer.send('ping')

const redisSave = () => {
  window.electron.ipcRenderer.send('redis', { name: '李怡然', age: 22 })
}

const redisSubscribe = () => {
  window.electron.ipcRenderer.send('redisSubscribe')
}

const mainMessage = ref('')
window.api.onRedisSubscribe((val) => {
  mainMessage.value = JSON.stringify(val)
})

</script>

<template>
  <img alt="logo" class="logo" src="./assets/electron.svg" />
  <div class="creator">Powered by electron-vite</div>
  <div class="text">
    Build an Electron app with
    <span class="vue">Vue</span>
    and
    <span class="ts">TypeScript</span>
  </div>
  <p class="tip">Please try pressing <code>F12</code> to open the devTool</p>
  <p class="tip">来自主进程的消息：{{ mainMessage }}</p>
  <div class="actions">
    <div class="action">
      <a href="https://electron-vite.org/" target="_blank" rel="noreferrer">Documentation</a>
    </div>
    <div class="action">
      <a target="_blank" rel="noreferrer" @click="ipcHandle">Send IPC</a>
    </div>
    <div class="action">
      <a target="_blank" rel="noreferrer" @click="redisSave">保存</a>
    </div>
    <div class="action">
      <a target="_blank" rel="noreferrer" @click="redisSubscribe">订阅</a>
    </div>
  </div>
  <Versions />
</template>
